package async;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThenCombineDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(100);
        CompletableFuture future1 = CompletableFuture.supplyAsync(() -> {
            System.out.println("future1：" + Thread.currentThread().getName());
            return "hello";
        }, executorService);
        CompletableFuture<String> future2 = CompletableFuture.supplyAsync(() -> {
            System.out.println("future2：" + Thread.currentThread().getName());
            return "itheima";
        }, executorService);
        CompletableFuture result = future1.thenCombineAsync(future2, (f1, f2) -> {
            System.out.println("result：" + Thread.currentThread().getName());
            return f1 + " " + f2;
        }, executorService);
        System.out.println(result.get());
        executorService.shutdown();
    }
}
